package com.zm.demo.sentinel.client.controller.config;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zoum
 * @create 2019/4/25 17:22
 */
public class SentinelRuleTest {

    public static void main(String[]args){
        testDegradeRule();
    }

    private static void testDegradeRule(){
        List<DegradeRule> rules = new ArrayList<DegradeRule>();
        DegradeRule rule = new DegradeRule();
        rule.setResource("getUserInfo");
        rule.setCount(1000);
        rule.setGrade(RuleConstant.DEGRADE_GRADE_RT);
        rule.setTimeWindow(60);
        rules.add(rule);
        System.out.println(JSONObject.toJSONString(rules));
    }

    private static void testFlowRule(){
        List<FlowRule> rules = new ArrayList<FlowRule>();
        FlowRule rule = new FlowRule();
        rule.setResource("getUserInfo");
        rule.setCount(1000);
        rule.setGrade(RuleConstant.DEGRADE_GRADE_RT);
        rules.add(rule);
        System.out.println(JSONObject.toJSONString(rules));
    }
}
